<template>
    <div>
        <a-modal
         v-model:visible="visible" 
         :title="formState.id?formState.view?'查看检验项目':'编辑检验项目':'新增检验项目'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="inspectionItems-add-edit-modal"
         :width="700"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="add-edit-form">
                    <a-form-item label="项目名称">
                        <a-input
                        v-model:value="formState.fxmmc"
                        placeholder="请输入项目名称"
                        v-decorator="[
                            'fxmmc', { initialValue:formState.fxmmc, rules: rules.fxmmc}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="标准规定">
                        <a-input
                        v-model:value="formState.fbzgd"
                        placeholder="请输入标准规定"
                        v-decorator="[
                            'fbzgd', { initialValue:formState.fbzgd, rules: rules.fbzgd}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="检验数据">
                        <a-input
                        v-model:value="formState.fjysj"
                        placeholder="请输入检验数据"
                        v-decorator="[
                            'fjysj', { initialValue:formState.fjysj, rules: rules.fjysj}
                        ]"/>
                    </a-form-item>
                    <a-form-item label="项目检验结论" class="flex-1-box">
                        <a-textarea 
                            placeholder="请输入项目检验结论"
                            v-model:value="formState.fxmjyjl"
                            :autosize="{ minRows: 3, maxRows: 10000 }"
                            v-decorator="[
                            'fxmjyjl', { initialValue:formState.fxmjyjl, rules: rules.fxmjyjl}
                        ]"
                        ></a-textarea>
                    </a-form-item>
                    <!-- <a-form-item label="备注" class="flex-1-box">
                        <a-textarea 
                            placeholder="请输入备注"
                            v-model:value="formState.fbz"
                            :autosize="{ minRows: 3, maxRows: 10000 }"
                        ></a-textarea>
                    </a-form-item> -->
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <!-- <a-button v-if="!formState.view" style="margin: 0 20px;" class="blue-btn" type="primary" @click="handleOk(true)">保存</a-button> -->
                <a-button style="margin-left: 20px;" v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">确定</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import { 
    spcyQyInfoupdateJyxm,
    spcyQyInfoaddJyxm,
 } from '../service/index'
import moment from 'moment'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
export default {
    components:{
        compSelector,
        commpVxeTable,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fxmmc: [{
                    required: true,
                    message: '请输入项目名称',
                    trigger: 'blur',
                }],
                fbzgd: [{
                    required: true,
                    message: '请输入标准规定',
                    trigger: 'blur',
                }],
                fjysj: [{
                    required: true,
                    message: '请输入检验数据',
                    trigger: 'blur',
                }],
                fxmjyjl: [{
                    required: true,
                    message: '请输入项目检验结论',
                    trigger: 'blur',
                }],
                
            },
            materialUnitList:[],
        }
    },
    watch:{

    },
    mounted(){
    },
    methods:{
        getData(val){
            this.formState = {}
            this.formState = val
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    let data = {
                        ...this.formState,
                        ...values
                    }
                    if(this.formState.id){
                        
                        spcyQyInfoupdateJyxm(data).then(res=>{
                            if(res.code == 200){
                                this.$message.success(res.message)
                                this.$emit('inspectionItemsSuccess')
                                this.visible = false
                            }else{
                                this.$message.warning(res.message)
                            }
                        })
                        
                        // this.$emit('editItem',{...this.formState,...values},val)
                    }else{
                        spcyQyInfoaddJyxm(data).then(res=>{
                            if(res.code == 200){
                                this.$message.success(res.message)
                                this.$emit('inspectionItemsSuccess')
                                this.visible = false
                            }else{
                                this.$message.warning(res.message)
                            }
                        })
                        // this.$emit('addItem',{...this.formState,...values},val)
                    }
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.inspectionItems-add-edit-modal{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
        }
        .ant-form-item-label{
            width: 110px;
        }
        .ant-form-item-control-wrapper{
            width: 180px;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>